home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / VideoToolbox / VideoToolboxSources / GDInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-29  |  5.2 KB  |  148 lines  |  [TEXT/KAHL]

  1. /*
  2. GDInfo.c
  3.  
  4. GDInfo fills the user-supplied VideoInfo record with all the descriptive
  5. information that can be obtained quickly from the driver and GDevice record
  6. without disturbing the screen. Under 1-bit QuickDraw it ignores the card->device
  7. field.
  8.  
  9. GDInfoTime fills the user-supplied VideoInfo record with the results of calling
  10. most of the routines in GDTime.c. Under 1-bit QuickDraw it ignores the "card->device"
  11. argument.
  12.  
  13. HISTORY:
  14. 4/16/93    dgp set pages=1 for 1-bit qd.
  15. 4/26/93    dgp    test HasDepth before relying on it.
  16. 4/27/93    dgp    replaced HasDepth by GDHasMode.
  17. */
  18. #include <VideoToolbox.h>
  19. #include "GDInfo.h"
  20.  
  21. OSErr GDInfo(VideoInfo *card)
  22. {
  23.     OSErr error;
  24.     short pixelSize,pages,d,mode,ok,hasDepthOk;
  25.     Rect r;
  26.     long qD;
  27.     ColorSpec cSpec;
  28.     char *s;
  29.     
  30.     Gestalt(gestaltQuickdrawVersion,&qD);
  31.     if(qD<gestalt8BitQD){
  32.         card->device=NULL;
  33.         sprintf(card->cardName,"%s","Original 1-bit QuickDraw");
  34.         sprintf(card->driverName,"%s","Original 1-bit QuickDraw");
  35.         for(d=1;d<6;d++)card->depth[d].pixelSize=0;
  36.         card->slot=0;
  37.         CopyQuickDrawGlobals();    // make sure qd is valid.
  38.         r=qd.screenBits.bounds;
  39.         card->width=r.right-r.left;
  40.         card->height=r.bottom-r.top;
  41.         card->depth[0].pixelSize=1;
  42.         card->depth[0].clutSize=2;
  43.         card->depth[0].pages=1;
  44.         card->depth[0].framesPerClutUpdate=NAN;
  45.         card->depth[0].framesPerClutUpdateHighPriority=NAN;
  46.         card->depth[0].framesPerClutUpdateQuickly=NAN;
  47.         card->depth[0].vblPerFrame=1.0;
  48.         card->d=0;
  49.         card->dacSize=1;
  50.         card->dacMask=((1<<card->dacSize)-1)<<(16 - card->dacSize);
  51.         card->basicTested=1;
  52.         return 0;
  53.     }
  54.     if(!card->basicTested){
  55.         // This info never changes, so get it only once
  56.         for(d=0;d<6;d++){
  57.             card->depth[d].pixelSize=0;
  58.             card->depth[d].mode=0;
  59.             card->depth[d].pages=0;
  60.         }
  61.         d=0;
  62.         for(mode=0x80;mode<=0x85 && d<6;mode++){
  63.             if(GDHasMode(card->device,mode,&pixelSize,&pages)){
  64.                 card->depth[d].mode=mode;
  65.                 card->depth[d].pixelSize=pixelSize;
  66.                 card->depth[d].pages=pages;
  67.                 d++;
  68.             }
  69.         }
  70.         sprintf(card->cardName,"%s",s=GDCardName(card->device));
  71.         DisposePtr(s);
  72.         if(GDVersion(card->device)==0)sprintf(card->driverName,"%#s"
  73.             ,GDName(card->device));
  74.         else sprintf(card->driverName,"%#s version %d"
  75.             ,GDName(card->device),GDVersion(card->device));
  76.         card->slot=GetDeviceSlot(card->device);
  77.         r=(**(**card->device).gdPMap).bounds;
  78.         card->width=r.right-r.left;
  79.         card->height=r.bottom-r.top;
  80.         card->dacSize=GDDacSize(card->device);        // Takes 200 µs.
  81.         card->dacMask=((1<<card->dacSize)-1)<<(16 - card->dacSize);
  82.         card->setEntriesQuickly=(GetCardType(card->device)!=0);
  83.         card->gdGetEntries=(0==GDGetEntries(card->device,0,0,&cSpec));
  84.         card->basicTested=1;
  85.     }
  86.     // d changes any time you call SetDepth, so update it every time.
  87.     for(d=0;d<6;d++)if(card->depth[d].mode==(**card->device).gdMode)card->d=d;
  88.     
  89.     // Collect information from the GDevice record
  90.     card->depth[card->d].pixelSize=(**(**card->device).gdPMap).pixelSize;
  91.     card->depth[card->d].clutSize=GDClutSize(card->device);
  92.     return 0;
  93. }
  94.  
  95. OSErr GDInfoTime(VideoInfo *card)
  96. {
  97.     OSErr error;
  98.     short clutSize=0,d=card->d;
  99.     double frames,s,missingFrames,frameRate;
  100.     long qD;
  101.     char blankLine[]="\r"    "          " "          " "          " "          "
  102.                             "          " "          " "          " "          " "\r";
  103.     printf(blankLine);    
  104.     printf("%d-bit pixels: timing CopyBits . . .\r",card->depth[d].pixelSize);
  105.     card->depth[d].movieRate=GDMovieRate(card->device,0);
  106.     printf(blankLine);    
  107.     printf("%d-bit pixels: timing CopyBitsQuickly . . .\r",card->depth[d].pixelSize);
  108.     card->depth[d].movieRateQuickly=GDMovieRate(card->device,1);
  109.     Gestalt(gestaltQuickdrawVersion,&qD);
  110.     if(qD>=gestalt8BitQD){
  111.         printf(blankLine);    
  112.         printf("%d-bit pixels: timing GDSetEntries . . .\r",card->depth[d].pixelSize);
  113.         error=GDTimeClut(card->device,GDSetEntries,clutSize,&s,&frames,&missingFrames,&frameRate);
  114.         if(error)frameRate=GDFrameRate(card->device);
  115.         card->depth[d].frameRate=frameRate;
  116.         card->depth[d].vblPerFrame=GDVBLRate(card->device)/frameRate;
  117.         card->depth[d].framesPerClutUpdate=frames;
  118.         card->depth[d].missingFramesPerClutUpdate=missingFrames;
  119.     }else{
  120.         card->depth[d].frameRate=GDFrameRate(NULL);
  121.         card->depth[d].vblPerFrame=1.0;
  122.         card->depth[d].framesPerClutUpdate=NAN;
  123.         card->depth[d].missingFramesPerClutUpdate=NAN;
  124.     }
  125.     if(qD>=gestalt8BitQD){
  126.         printf(blankLine);    
  127.         printf("%d-bit pixels: timing GDSetEntriesByTypeHighPriority . . .\r",card->depth[d].pixelSize);
  128.         error=GDTimeClut(card->device,GDSetEntriesByTypeHighPriority,clutSize,&s,&frames,&missingFrames,&frameRate);
  129.         card->depth[d].framesPerClutUpdateHighPriority=frames;
  130.         card->depth[d].missingFramesPerClutUpdateHighPriority=missingFrames;
  131.     }else{
  132.         card->depth[d].framesPerClutUpdateHighPriority=NAN;
  133.         card->depth[d].missingFramesPerClutUpdateHighPriority=NAN;
  134.     }
  135.     if(qD>=gestalt8BitQD && GetCardType(card->device)){
  136.         printf(blankLine);    
  137.         printf("%d-bit pixels: timing SetEntriesQuickly . . .\r",card->depth[d].pixelSize);
  138.         error=GDTimeClut(card->device,SetEntriesQuickly,clutSize,&s,&frames,&missingFrames,&frameRate);
  139.         card->depth[d].framesPerClutUpdateQuickly=frames;
  140.         card->depth[d].missingFramesPerClutUpdateQuickly=missingFrames;
  141.     }else{
  142.         card->depth[d].framesPerClutUpdateQuickly=NAN;
  143.         card->depth[d].missingFramesPerClutUpdateQuickly=NAN;
  144.     }
  145.     printf(blankLine);    
  146.     card->timeTested=1;
  147.     card->depth[d].timeTested=1;
  148. }